<template>
  <div class="app-container">
    <!-- 搜索工作栏 -->
    <el-form v-show="showSearch" ref="queryForm" :inline="true" :model="queryParams" label-width="68px" size="small">
      <el-form-item label="名字" prop="name">
        <el-input v-model.trim="queryParams.name" clearable placeholder="请输入名字" @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="类型" prop="type">
        <el-select v-model="queryParams.type" clearable placeholder="请选择类型" size="small">
          <el-option v-for="dict in this.getDictDatas(DICT_TYPE.SYSTEM_OPERATE_GUIDE_TYPE)"
                     :key="dict.value" :label="dict.label" :value="dict.value"/>
        </el-select>
      </el-form-item>
      <el-form-item label="所属模块" prop="module">
        <el-select v-model="queryParams.module" clearable placeholder="请选择所属模块" size="small">
          <el-option v-for="dict in this.getDictDatas(DICT_TYPE.SYSTEM_OPERATE_GUIDE_MODULE)"
                     :key="dict.value" :label="dict.label" :value="dict.value"/>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button icon="el-icon-search" type="primary" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <!-- 操作工具栏 -->
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button icon="el-icon-plus" plain size="mini" type="primary"
                   @click="openForm(undefined)">新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button :loading="exportLoading" icon="el-icon-download" plain
                   size="mini"
                   type="warning"
                   @click="handleExport">导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="list" :show-overflow-tooltip="true" :stripe="true" :height="height" >
      <el-table-column align="center" label="ID" prop="id"/>
      <el-table-column align="center" label="名字" prop="name"/>
      <el-table-column align="center" label="类型" prop="type">
        <template v-slot="scope">
          <dict-tag :type="DICT_TYPE.SYSTEM_OPERATE_GUIDE_TYPE" :value="scope.row.type"/>
        </template>
      </el-table-column>
      <el-table-column align="center" label="所属模块" prop="module">
        <template v-slot="scope">
          <dict-tag :type="DICT_TYPE.SYSTEM_OPERATE_GUIDE_MODULE" :value="scope.row.module"/>
        </template>
      </el-table-column>
      <el-table-column align="center" label="图片地址" prop="picUrl"/>
      <el-table-column label="图片内容" align="center" prop="picUrl" min-width="150px">
        <template v-slot="scope">
          <image-preview :src="scope.row.picUrl" :width="'100px'"></image-preview>
        </template>
      </el-table-column>
      <el-table-column align="center" label="排序" prop="sort"/>
      <el-table-column align="center" class-name="small-padding fixed-width" label="操作">
        <template v-slot="scope">
          <el-button icon="el-icon-edit" size="mini" type="text"
                     @click="openForm(scope.row.id)">修改
          </el-button>
          <el-button icon="el-icon-delete" size="mini" type="text"
                     @click="handleDelete(scope.row)">删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <pagination v-show="total > 0" :limit.sync="queryParams.pageSize" :page.sync="queryParams.pageNo" :total="total"
                @pagination="getList"/>
    <!-- 对话框(添加 / 修改) -->
    <OperateGuideForm ref="formRef" @success="getList"/>
  </div>
</template>

<script>
import * as OperateGuideApi from '@/api/system/operateguide';
import OperateGuideForm from './OperateGuideForm.vue';
import ImagePreview from "@/components/ImagePreview/index.vue";

export default {
  name: "OperateGuide",
  components: {
    ImagePreview,
    OperateGuideForm
  },
  data() {
    return {
      height:300,
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 系统操作引导列表
      list: [],
      // 是否展开，默认全部展开
      isExpandAll: true,
      // 重新渲染表格状态
      refreshTable: true,
      // 选中行
      currentRow: {},
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        name: null,
        type: null,
        module: null,
      },
    };
  },
  created() {
    this.getList();
    this.calcHeight()
  },
  methods: {
    calcHeight() {
                let clientHeight = window.outerHeight
                this.height = clientHeight - 235 - 100
            },
    /** 查询列表 */
    async getList() {
      try {
        this.loading = true;
        const res = await OperateGuideApi.getOperateGuidePage(this.queryParams);
        this.list = res.data.list;
        this.total = res.data.total;
      } finally {
        this.loading = false;
      }
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNo = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 添加/修改操作 */
    openForm(id) {
      this.$refs["formRef"].open(id);
    },
    /** 删除按钮操作 */
    async handleDelete(row) {
      const id = row.id;
      await this.$modal.confirm('是否确认删除系统操作引导编号为"' + id + '"的数据项?')
      try {
        await OperateGuideApi.deleteOperateGuide(id);
        await this.getList();
        this.$modal.msgSuccess("删除成功");
      } catch {
      }
    },
    /** 导出按钮操作 */
    async handleExport() {
      await this.$modal.confirm('是否确认导出所有系统操作引导数据项?');
      try {
        this.exportLoading = true;
        const res = await OperateGuideApi.exportOperateGuideExcel(this.queryParams);
        this.$download.excel(res, '系统操作引导.xls');
      } catch {
      } finally {
        this.exportLoading = false;
      }
    },
  }
};
</script>
